package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.HotelExpense;

public class HotelExpenseDAOImpl extends BaseHibernateDAOImpl<HotelExpense> implements HotelExpenseDAO {

	public HotelExpense getHotelExpenseByHotelExpenseID(String heID) {
		HotelExpense hotelExpense;
		try {
			hotelExpense = (HotelExpense) getSession().get(HotelExpense.class, heID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return hotelExpense;
	}

	@SuppressWarnings("unchecked")
	public List<HotelExpense> getAllHotelExpenseByCondition(String hql) {
		List<HotelExpense> hotelExpenses;
		try {
			Query query = getSession().createQuery("from HotelExpense" + hql);
			hotelExpenses = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return hotelExpenses;
	}

	@SuppressWarnings("unchecked")
	public List<HotelExpense> getAllHotelExpenseByConditionByPage(String hql, int currentPage, int lineSize) {
		List<HotelExpense> hotelExpenses;
		try {
			Query query = getSession().createQuery("from HotelExpense" + hql);
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			hotelExpenses = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return hotelExpenses;
	}


}
